package com.redsoil.house.ui.mine.fragment;

import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.redsoil.house.R;
import com.redsoil.house.base.RootFragment;
import com.redsoil.house.ui.mine.contract.MineContract;
import com.redsoil.house.ui.mine.contract.MineInfoContract;
import com.redsoil.house.ui.mine.presenter.MineInfoPresenter;
import com.redsoil.house.ui.mine.presenter.MinePresenter;
import com.redsoil.house.widget.PropertyFileItem;
import com.redsoil.house.widget.TopMenuBarItem;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * 资产主界面
 */
public class MineFragment extends RootFragment<MinePresenter> implements MineContract.View {

    public static final int FIRST = 0;
    public static final int SECOND = 1;

    private SupportFragment[] mFragments = new SupportFragment[2];

    @BindView(R.id.top_bar_mine_info)
    TopMenuBarItem top_bar_mine_info;

    @BindView(R.id.top_bar_mine_special)
    TopMenuBarItem top_bar_mine_special;


    public static MineFragment newInstance() {
        Bundle args = new Bundle();

        MineFragment fragment = new MineFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initEventAndData() {
        SupportFragment firstFragment = findFragment(MineInfoFragment.class);

        if (firstFragment == null) {
            mFragments[FIRST] = MineInfoFragment.newInstance();
            mFragments[SECOND] = MineSpecialFragment.newInstance();

            loadMultipleRootFragment(R.id.mine_container, FIRST,
                    mFragments[FIRST], mFragments[SECOND]);

        } else {
            // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
            // 这里我们需要拿到mFragments的引用,也可以通过getChildFragmentManager.findFragmentByTag自行进行判断查找(效率更高些),用下面的方法查找更方便些
            mFragments[FIRST] = firstFragment;
            mFragments[SECOND] = findFragment(MineSpecialFragment.class);
        }
        topBarInfoClick();
    }

    @OnClick(R.id.top_bar_mine_info)
    void topBarInfoClick() {
        top_bar_mine_info.setSelected(true);
        top_bar_mine_special.setSelected(false);
        showHideFragment(mFragments[0], mFragments[1]);
    }

    @OnClick(R.id.top_bar_mine_special)
    void topBarSpecialClick() {
        top_bar_mine_info.setSelected(false);
        top_bar_mine_special.setSelected(true);
        showHideFragment(mFragments[1], mFragments[0]);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }
}
